/**
 * Created by IntelliJ IDEA.
 * User: Bezdelnick
 * Date: 9/28/12
 * Time: 5:16 PM
 * To change this template use File | Settings | File Templates.
 */
package vplib.maple {
import vplib.model.PhysicsProperty;

public class LikeVelocityUtil {
    public function LikeVelocityUtil() {
        //
    }

    public static function setVariable(data:String, variableName:String, variableNewValue:String):String {
        var result:String;
        var varDef:String = "&{" + variableName + "}";
        var varPosition:int = data.indexOf(varDef);
        if (varPosition >=0) {
            var firstPart:String = data.substring(0, varPosition);
            var secondPart:String = data.substring(varPosition + varDef.length, data.length);
            return firstPart + variableNewValue + secondPart;
        } else
            return data;
    }

    public static function createAndInitializeVariable(componentUniqueId:String, property:PhysicsProperty):String {
        var mask:String = "&{id}__&{prop}:=&{value}";
        mask = setVariable(mask, "id", componentUniqueId);
        mask = setVariable(mask, "prop", property.name);
        mask = setVariable(mask, "value", String(property.value));
        return mask;
    }

    public static function createAndInitializeVariableField(componentUniqueId:String, property:PhysicsProperty):String {
        var mask:String = "&{id}__&{prop}__field:=&{value}";
        mask = setVariable(mask, "id", componentUniqueId);
        mask = setVariable(mask, "prop", property.name);
        mask = setVariable(mask, "value", String(property.value));
        return mask;
    }
}
}
